package org.darkforest.vo;

import org.darkforest.model.Cart;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by valentina on 15/5/15.
 * 购物车ajax返回对象
 */
public class CartInfoAjaxVo {

    private String success;
    private String info;
    private Integer cartQty=0;
    private BigDecimal subtotal = new BigDecimal("0");
    private Integer itemsCount=0;
    private List<Cart> list;
    private List<Cart> cartStorelist;
    public CartInfoAjaxVo(){}

    public CartInfoAjaxVo(List<Cart> carts){
        this.list = carts;
        //列表有数据时循环累积数量以及总价
        if(carts!=null && carts.size()>0){
            for(Cart car:carts){
                this.setCartQty((int)car.getGoodsNum());
                this.setSubtotal(this.getSubtotal().add(car.getGoodsPrice().multiply(new BigDecimal(car.getGoodsNum()))));
            }
        }
    }
//    public CartInfoAjaxVo(List<Cart> carts,List<Cart> stores){
//        this.list = carts;
//        //列表有数据时循环累积数量以及总价
//        if(carts!=null && carts.size()>0){
//            for(Cart car:carts){
//                this.setCartQty((int)car.getGoodsNum());
//                this.setSubtotal(this.getSubtotal().add(car.getGoodsPrice().multiply(new BigDecimal(car.getGoodsNum()))));
//            }
//        }
//        this.cartStorelist=stores;
//    }
    public Integer getCartQty() {
        int i = 0;
        for(Cart cart:this.list){
            i+=cart.getGoodsNum();
        }


        return i;
    }

    public void setCartQty(Integer cartQty) {
        this.cartQty = cartQty;
    }

    public BigDecimal getSubtotal() {
        return subtotal;
    }

    public void setSubtotal(BigDecimal subtotal) {
        this.subtotal = subtotal;
    }

    public Integer getItemsCount() {
        return itemsCount;
    }

    public void setItemsCount(Integer itemsCount) {
        this.itemsCount = itemsCount;
    }

    public List<Cart> getList() {
        return list;
    }

    public void setList(List<Cart> list) {
        this.list = list;
    }

    public String getSuccess() {
        return success;
    }

    public void setSuccess(String success) {
        this.success = success;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public List<Cart> getCartStorelist() {
        return cartStorelist;
    }

    public void setCartStorelist(List<Cart> cartStorelist) {
        this.cartStorelist = cartStorelist;
    }

}
